package com.devilvan.reviewWordCount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text,Text,LongWritable> {
    private Text resultKey;
    private LongWritable resultValue;

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        resultKey = new Text();
        resultValue = new LongWritable(1);
    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        for (String field : fields) {
            resultKey.set(field);
            context.write(resultKey,resultValue);
        }
    }
}
